//
//  DrawCartoonViewController.m
//  drawacartoon
//
//  Created by Ji Hu on 12-7-25.
//  Copyright (c) 2012年 爱辅导. All rights reserved.
//

#import "DrawCartoonViewController.h"
#import "Log.h"
#import "DrawPageVIew.h"

@interface DrawCartoonViewController ()

@end

@implementation DrawCartoonViewController

@synthesize drawCartoonDelegate=_drawCartoonDelegate;
@synthesize pageviewContainer=_pageviewContainer;

-(void)didReceiveMemoryWarning{
    [Log warning:@"draw cartoon controller receive memory warning!"];
}

-(void)dealloc{
    self.drawCartoonDelegate=nil;
    self.pageviewContainer=nil;
    if (_drawCartoonPageContainer) {
        [_drawCartoonPageContainer removeFromSuperview];
        [_drawCartoonPageContainer release];
        _drawCartoonPageContainer = nil;
    }
    [super dealloc];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    if (_drawCartoonPageContainer==nil) {
        _drawCartoonPageContainer = [[DrawCartoonPageContainer alloc] initWithChildClass:[DrawPageVIew class] withFrame:self.pageviewContainer.bounds];
        _drawCartoonPageContainer.delegate=self;
        [self.pageviewContainer addSubview:_drawCartoonPageContainer];
    }
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

-(void)didAddPageToHead:(id)removedTailPage withAddedHeadPage:(id)headpage{
    [headpage loadFromFile];
}

-(void)didAddPageToTail:(id)removedHeadPage withAddedTailPage:(id)tailPage{
    [tailPage loadFromFile];
}

-(void)didAddChild:(id)child withTag:(NSInteger)tag{
    [child loadFromFile];
}

-(void)nextClick:(id)sender{
    [_drawCartoonPageContainer showNextPage];
}

-(void)exitClick:(id)sender{
    [self.drawCartoonDelegate exitDrawCartoon];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
	return YES;
}

@end
